package test.org.offsync.nio

import java.nio.channels.{SelectionKey => JavaSelectionKey}
import java.util.concurrent.atomic.AtomicInteger
import org.junit.runner.RunWith
import org.offsync.async.AsyncSelector

@RunWith(classOf[org.specs2.runner.JUnitRunner])
class SpecSelector extends org.specs2.mutable.SpecificationWithJUnit {
  "Selector" should {
    val selector = new AsyncSelector()
    "allow execution in selector thread" in {
      val counter = new AtomicInteger(0)
      selector.execute {
        counter.incrementAndGet()
      }
      counter.incrementAndGet()
      Thread.sleep(100)
      selector.dispose()
      counter.get() must_== 2
    }
  }
}
